package xiaohuo.fancyring.util

import org.bukkit.entity.Player
import java.util.*

private val allCoolDown = mutableMapOf<String, MutableMap<UUID, Long>>()

fun Player.getCoolDown(id: String, time: Long): Long {
    // 冷却组未被调用过
    if (id !in allCoolDown) {
        return -1
    }
    val latest = (System.currentTimeMillis() - allCoolDown[id]!!.getOrDefault(uniqueId, 0)) / 1000
    if (latest >= time) {
        return -1
    }
    return time - latest
}

fun Player.setCoolDown(id: String) {
    allCoolDown.getOrPut(id) {
        mutableMapOf()
    }[uniqueId] = System.currentTimeMillis()
}